package com.myres.service;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.transaction.annotation.Transactional;

import com.myres.dao.CategoryDao;
import com.myres.model.Category;

public class CategoryService {
	private CategoryDao categoryDao;

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public void delete(int id) {
		categoryDao.delete(id);
	}

	public void delete(Category category) {
		categoryDao.delete(category);
	}

	public List<Category> findAll() {
		return categoryDao.findAll();
	}

	public List<Category> findAllInRange(Integer startWith, Integer size) {
		return categoryDao.findAllInRange(startWith, size);
	}

	/**
	 * 
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as above.
	 * @return
	 */
	public List<Category> findAllOrderByPriorityInRange(Integer startWith,
			Integer size) {
		return categoryDao.findAllOrderByPriorityInRange(startWith, size);
	}

	public List<Category> findByName(String name) {
		return categoryDao.findByName(name);
	}

	/**
	 * 
	 * @param name
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as above.
	 * @return
	 */
	public List<Category> findByNameOrderByPriorityInRange(String name,
			Integer startWith, Integer size) {
		return categoryDao.findByNameOrderByPriorityInRange(name, startWith,
				size);
	}

	public Category get(int id) {
		return categoryDao.get(id);
	}

	public int save(Category category) {
		return categoryDao.save(category);
	}

	public int saveOrUpdate(Category category) {
		return categoryDao.saveOrUpdate(category);
	}

	public void update(Category category) {
		categoryDao.update(category);
	}
}
